<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<p>打字小游戏：</p>
<p><input type="text" id="showCode" name="userName"></p>
<script>
    var showCode = document.querySelector("#showCode");
    var body = document.querySelector("body");
    var div = document.createElement("div");
    div.className = "code";
    div.style.background = "rgba(0,0,0,0.5)";
    div.style.width = "300px";
    div.style.height = "300px";
    div.style.fontSize = "200px";
    div.style.lineHeight = "300px";
    div.style.fontWeight = "300px";
    div.style.textAlign = "center";
    showCode.onkeydown = function (event) {
        //console.log(event);
        div.innerHTML = event.key;
        body.appendChild(div);
    }
</script>
</body>
</html>